import React from 'react';
import { Button } from 'antd';
import { connect } from 'umi';

import EmptyPlaceHolder from '@/pages/SalaryManage/components/EmptyPlaceHolder';
import { personalIncomeTaxService as service } from '@/services/salaryManage/statistics';
import { commonColumn, amountColumn } from '@/pages/SalaryManage/utils/TableUtil';
import { goToSalaryStatisticsDetail } from '@/pages/SalaryManage/utils/pageNavigateUtil'
import modelFactory from '@/pages/SalaryManage/Statistics/statisticsModelFactory';
import salaryStyle from '@/pages/SalaryManage/salaryManage.less';

const namespace = 'personalTaxStatisticsModel';
const personalTaxStatisticsModel = modelFactory.generateModel({ namespace, service });

const EmployeeSalaryCell = connect(
    ({ statisticsModel }) => ({ organizationCode: statisticsModel.selectOrganizationCode })
)(({ employeeName, employeeCode, organizationCode }) => <>{
    employeeName
        ? <Button
            type="link"
            className={salaryStyle.linkBtn}
            onClick={() => goToSalaryStatisticsDetail({ employeeCode, organizationCode })}
        >
            {employeeName}
        </Button>
        : <EmptyPlaceHolder />
}</>);

Object.assign(personalTaxStatisticsModel.state, {
    title: '个税【汇总表】',
    subTitle: '',

    tableHeader: [
        commonColumn({
            title: '年月',
            dataIndex: 'yearMonth',
            width: 120,
            fixed: true
        }),
        {
            title: '姓名',
            dataIndex: 'name',
            width: 100,
            fixed: true,
            render(text, record) {
                return <EmployeeSalaryCell employeeName={text} employeeCode={record.employeeCode} />;
            }
        },
        commonColumn({
            title: '工号',
            dataIndex: 'employeeNo',
            width: 100,
            fixed: true
        }),
        commonColumn({
            title: '证照号码',
            dataIndex: 'cardNo',
            width: 200
        }),
        commonColumn({
            title: '入职日期',
            dataIndex: 'startDateStr',
            align: 'center',
            width: 120
        }),
        commonColumn({
            title: '状态',
            dataIndex: 'statusName'
        }),
        commonColumn({
            title: '组织机构',
            dataIndex: 'departmentName',
            width: 220
        }),
        commonColumn({
            title: '岗位',
            dataIndex: 'dutyName',
            width: 150,
            ellipsis: true
        }),
        commonColumn({
            title: '职位',
            dataIndex: 'positionName',
            width: 150,
            ellipsis: true
        }),
        commonColumn({
            title: '职级',
            dataIndex: 'rankName',
            width: 150,
            ellipsis: true
        }),
        amountColumn({
            title: '本月收入',
            dataIndex: 'encryptCurrIncomeAmt'
        }),
        {
            title: '险金（本月）',
            dataIndex: 'monthfund',
            children: [
                amountColumn(
                    {
                        title: '养老保险（个人）',
                        dataIndex: 'encryptOldPersonAmt',
                        width: 160
                    },
                    { color: true }
                ),
                amountColumn(
                    {
                        title: '失业保险（个人）',
                        dataIndex: 'encryptUnemployPersonAmt',
                        width: 160
                    },
                    { color: true }
                ),
                amountColumn(
                    {
                        title: '医疗保险（个人）',
                        dataIndex: 'encryptHospitalPersonAmt',
                        width: 160
                    },
                    { color: true }
                ),
                amountColumn(
                    {
                        title: '生育保险（个人）',
                        dataIndex: 'encryptBirthPersonAmt',
                        width: 160
                    },
                    { color: true }
                ),
                amountColumn(
                    {
                        title: '工伤保险（个人）',
                        dataIndex: 'encryptHarmPersonAmt',
                        width: 160
                    },
                    { color: true }
                ),
                amountColumn(
                    {
                        title: '大病保险（个人）',
                        dataIndex: 'encryptIllPersonAmt',
                        width: 160
                    },
                    { color: true }
                ),
                amountColumn(
                    {
                        title: '公积金（个人）',
                        dataIndex: 'encryptFundPersonAmt',
                        width: 160
                    },
                    { color: true }
                )
            ]
        },
        amountColumn({
            title: '本月免征额',
            dataIndex: 'encryptCurrExpenseAmt'
        }),
        amountColumn({
            title: '本月专项扣款合计',
            dataIndex: 'encryptCurrSpecialAmt',
            width: 160
        }),
        amountColumn({
            title: '本月免税收入',
            dataIndex: 'encryptCurrNotaxAmt'
        }),
        amountColumn({
            title: '本月应税收入',
            dataIndex: 'encryptCurrTaxIncomeAmt'
        }),
        amountColumn({
            title: '本月应缴个税',
            dataIndex: 'encryptTaxAmt'
        }),
        amountColumn({
            title: (
                <div className={salaryStyle.textCenter}>
                    <div>累计收入</div>
                    <div>（截止当月）</div>
                </div>
            ),
            dataIndex: 'encryptTotalIncomeAmt'
        }),
        {
            title: '累计险金（截止当月）',
            dataIndex: 'totalfund',
            children: [
                amountColumn(
                    {
                        title: '养老保险（个人）',
                        dataIndex: 'encryptTotalFundOldAmt',
                        width: 160
                    },
                    { color: true }
                ),
                amountColumn(
                    {
                        title: '失业保险（个人）',
                        dataIndex: 'encryptTotalFundUnemployAmt',
                        width: 160
                    },
                    { color: true }
                ),
                amountColumn(
                    {
                        title: '医疗保险（个人）',
                        dataIndex: 'encryptTotalFundHospitalAmt',
                        width: 160
                    },
                    { color: true }
                ),

                amountColumn(
                    {
                        title: '生育保险（个人）',
                        dataIndex: 'encryptTotalFundBirthBaseAmt',
                        width: 160
                    },
                    { color: true }
                ),
                amountColumn(
                    {
                        title: '工伤保险（个人）',
                        dataIndex: 'encryptTotalFundHarmBaseAmt',
                        width: 160
                    },
                    { color: true }
                ),

                amountColumn(
                    {
                        title: '大病保险（个人）',
                        dataIndex: 'encryptTotalFundIllBaseAmt',
                        width: 160
                    },
                    { color: true }
                ),
                amountColumn(
                    {
                        title: '公积金（个人）',
                        dataIndex: 'encryptTotalFundHouseAmt',
                        width: 160
                    },
                    { color: true }
                )
            ]
        },
        amountColumn({
            title: (
                <div className={salaryStyle.textCenter}>
                    <div>累计免征额</div>
                    <div>（截止当月）</div>
                </div>
            ),
            dataIndex: 'encryptTotalExpenseAmt'
        }),
        amountColumn({
            title: (
                <div className={salaryStyle.textCenter}>
                    <div>累计专项扣款</div>
                    <div>（截止当月）</div>
                </div>
            ),
            dataIndex: 'encryptTotalSpecialAmt'
        }),
        amountColumn({
            title: (
                <div className={salaryStyle.textCenter}>
                    <div>累计免税收入</div>
                    <div>（截止当月）</div>
                </div>
            ),
            dataIndex: 'encryptTotalNotaxAmt'
        }),
        amountColumn({
            title: (
                <div className={salaryStyle.textCenter}>
                    <div>累计应税收入</div>
                    <div>（截止当月）</div>
                </div>
            ),
            dataIndex: 'encryptTotalTaxIncomeAmt'
        }),
        amountColumn(
            {
                title: (
                    <div className={salaryStyle.textCenter}>
                        <div>累计应缴个税</div>
                        <div>（截止当月）</div>
                    </div>
                ),
                dataIndex: 'encryptTotalPayableTaxAmt'
            },
            { color: true }
        )
    ],
    summaryFieldsRender: () => [
        { yearMonth: '合计' },
        'encryptCurrIncomeAmt',
        'encryptOldPersonAmt',
        'encryptUnemployPersonAmt',
        'encryptHospitalPersonAmt',
        'encryptBirthPersonAmt',
        'encryptHarmPersonAmt',
        'encryptFundPersonAmt',
        'encryptCurrExpenseAmt',
        'encryptCurrSpecialAmt',
        'encryptCurrNotaxAmt',
        'encryptCurrTaxIncomeAmt',
        'encryptTaxAmt',
        'encryptTotalIncomeAmt',
        'encryptTotalFundOldAmt',
        'encryptTotalFundUnemployAmt',
        'encryptTotalFundHospitalAmt',
        'encryptTotalFundBirthBaseAmt',
        'encryptTotalFundHarmBaseAmt',
        'encryptTotalFundHouseAmt',
        'encryptTotalExpenseAmt',
        'encryptTotalSpecialAmt',
        'encryptTotalNotaxAmt',
        'encryptTotalTaxIncomeAmt',
        'encryptTotalPayableTaxAmt',
        'encryptIllPersonAmt',
        'encryptTotalFundIllBaseAmt'
    ]
});

export default personalTaxStatisticsModel;
